/*
 * Copyright (c) 2011, Nikolaus Moll
 * All rights reserved.
 */
package net.miblounge.gradecalculator.core.serialization;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import net.miblounge.gradecalculator.core.enums.CourseType;
import net.miblounge.gradecalculator.core.enums.CourseTypeList;


public final class CourseTypeListAdapter extends XmlAdapter<String, CourseTypeList> {

	@Override
	public CourseTypeList unmarshal(final String v) throws Exception {
		final CourseTypeList result = new CourseTypeList();
		if (!v.equals("")) { 
			final String[] values = v.split(" ");
			for (final String value : values) {
				final CourseType type = CourseType.valueOf(value);
				result.add(type);
			}
		}
		return result;
	}

	@Override
	public String marshal(final CourseTypeList v) throws Exception {
		String result = "";
		for (CourseType type : v) {
			result = result + " " + type.getAbbreviation();
		}
		return result.trim();
	}

}